Include Nur.DateFormat

/// Creator:      gaoruishan
/// CreatDate:    2025-08-25
/// Description:  地点巡视汇总表
Class Nur.MNISV3.SpotTourRec Extends %Persistent
{

/// 巡视日期
Property DHCNurTourDate As %Library.Date(FORMAT = 1) [ InitialExpression = {+$p($h,",",1)}, Required, SqlColumnNumber = 2 ];

/// 巡视时间
Property DHCNurTourTime As %Library.Time [ InitialExpression = {+$p($h,",",2)}, Required, SqlColumnNumber = 3 ];

/// 巡视人
Property DHCNurTourUser As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 4 ];

/// 巡视地点类型
Property DHCNurTourSpot As %Library.String [ SqlColumnNumber = 5 ];

/// 巡视所在病区
Property DHCNurTourCtlocDR As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 6 ];

/// 对应 item1~15的类型
Property ItemType As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 7 ];

Property Item1 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 8 ];

Property Item2 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 9 ];

Property Item3 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 10 ];

Property Item4 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 11 ];

Property Item5 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 12 ];

Property Item6 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 13 ];

Property Item7 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 14 ];

Property Item8 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 15 ];

Property Item9 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 16 ];

Property Item10 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 17 ];

Property Item11 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 18 ];

Property Item12 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 19 ];

Property Item13 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 20 ];

Property Item14 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 21 ];

Property Item15 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 22 ];

Property Item16 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 23 ];

Property Item17 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 24 ];

Property Item18 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 25 ];

Property Item19 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 26 ];

Property Item20 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 27 ];

/// 条码类型
Property DHCNurTourBarcodeType As %Library.String [ SqlColumnNumber = 28 ];

Index TourDateCtloc On DHCNurTourCtlocDR;

Index TourDateSpot On (DHCNurTourDate, DHCNurTourSpot);

Index TourUser On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourUser);

/// Description:  巡视保存
/// Input：       parr:数据串(key|value^key|value),id:id,userId:用户ID
/// other:        w ##class(Nur.MNISV3.SpotTourRec).Save()
ClassMethod Save(parr As %String, id As %String, userId As %String, parrJson = "") As %String
{
    s tmp=""
    s a=##class(web.DHCMGNurComm).setmoudtmp(parr,.tmp)
    i (id=""){
        s rec=##class(Nur.MNISV3.SpotTourRec).%New()
    }else{
        s rec=##class(Nur.MNISV3.SpotTourRec).%OpenId(id)
    }
    i '$d(tmp("DHCNurTourDate"))  d
    .s tmp("DHCNurTourDate")=+$h
    e  d
    .i tmp("DHCNurTourDate")["-" s tmp("DHCNurTourDate")=$zdh(tmp("DHCNurTourDate"),3)
    .i tmp("DHCNurTourDate")["/" s tmp("DHCNurTourDate")=$zdh(tmp("DHCNurTourDate"),1)  
    i '$d(tmp("DHCNurTourTime"))  d
    .s tmp("DHCNurTourTime")=$p($h,",",2)
    e  d
    .i tmp("DHCNurTourTime")[":" s tmp("DHCNurTourTime")=$zth(tmp("DHCNurTourTime"))

    i $d(tmp("DHCNurTourDate")) s rec.DHCNurTourDate=tmp("DHCNurTourDate")
    i $d(tmp("DHCNurTourTime")) s rec.DHCNurTourTime=tmp("DHCNurTourTime")
    i $d(tmp("DHCNurTourCtlocDR")) s rec.DHCNurTourCtlocDR=tmp("DHCNurTourCtlocDR")
    i $d(tmp("DHCNurTourSpot")) s rec.DHCNurTourSpot=tmp("DHCNurTourSpot")
    i $d(tmp("DHCNurTourBarcodeType")) s rec.DHCNurTourBarcodeType=tmp("DHCNurTourBarcodeType")

    //处理 parrJson 对象
    //"{""5||11"":""jxjxjxjjx"",""5||10"":""hshshh"",""5||2"":""22"",""5||1"":""36.5"",""5||4"":""44"",""5||3"":""33"",""5||6"":""66"",""5||5"":""55"",""5||8"":""有"",""5||7"":""45"",""5||9"":""皮疹^寒战^胸闷""}
    i $g(parrJson)'="" {
        s itemType=""
        s set=##class(Nur.MNISV3.Common.JSON).Decode(parrJson)
        s key=set.Next("")
        while (key'="") {
            s value=set.GetAt(key)
            i key["||" { //分隔字符 第一个是类型
                s itemType=$p(key,"||",1)
                s itemIndex=$p(key,"||",2)
                s itm="Item"_itemIndex  
                if $g(value)'="" s $ZOBJPROPERTY(rec,itm)=value
            }
            s key=set.Next(key)
           
        }
        i itemType'="" s $ZOBJPROPERTY(rec,"ItemType")=itemType
    }
    
    s rec.DHCNurTourUser=userId
    s sc=rec.%Save()
    q:$$$ISERR(sc) "err:"_$SYSTEM.Status.GetErrorText(sc)
    q rec.%Id()
}

Storage Default
{
<Data name="SpotTourRecDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>DHCNurTourDate</Value>
</Value>
<Value name="3">
<Value>DHCNurTourTime</Value>
</Value>
<Value name="4">
<Value>DHCNurTourUser</Value>
</Value>
<Value name="5">
<Value>DHCNurTourBarcodeType</Value>
</Value>
<Value name="6">
<Value>DHCNurTourCtlocDR</Value>
</Value>
<Value name="7">
<Value>ItemType</Value>
</Value>
<Value name="8">
<Value>Item1</Value>
</Value>
<Value name="9">
<Value>Item2</Value>
</Value>
<Value name="10">
<Value>Item3</Value>
</Value>
<Value name="11">
<Value>Item4</Value>
</Value>
<Value name="12">
<Value>Item5</Value>
</Value>
<Value name="13">
<Value>Item6</Value>
</Value>
<Value name="14">
<Value>Item7</Value>
</Value>
<Value name="15">
<Value>Item8</Value>
</Value>
<Value name="16">
<Value>Item9</Value>
</Value>
<Value name="17">
<Value>Item10</Value>
</Value>
<Value name="18">
<Value>Item11</Value>
</Value>
<Value name="19">
<Value>Item12</Value>
</Value>
<Value name="20">
<Value>Item13</Value>
</Value>
<Value name="21">
<Value>Item14</Value>
</Value>
<Value name="22">
<Value>Item15</Value>
</Value>
<Value name="23">
<Value>Item16</Value>
</Value>
<Value name="24">
<Value>Item17</Value>
</Value>
<Value name="25">
<Value>Item18</Value>
</Value>
<Value name="26">
<Value>Item19</Value>
</Value>
<Value name="27">
<Value>Item20</Value>
</Value>
<Value name="28">
<Value>DHCNurTourSpot</Value>
</Value>
</Data>
<DataLocation>^Nur.MNISV3.SpotTourRecD</DataLocation>
<DefaultData>SpotTourRecDefaultData</DefaultData>
<ExtentSize>1</ExtentSize>
<IdLocation>^Nur.MNISV3.SpotTourRecD</IdLocation>
<IndexLocation>^Nur.MNISV3.SpotTourRecI</IndexLocation>
<Property name="%%CLASSNAME">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="%%ID">
<AverageFieldSize>3</AverageFieldSize>
<Selectivity>1</Selectivity>
</Property>
<Property name="DHCNurTourCtlocDR">
<AverageFieldSize>3</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourDate">
<AverageFieldSize>5</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourSpot">
<AverageFieldSize>6</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourTime">
<AverageFieldSize>4</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourUser">
<AverageFieldSize>7</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item1">
<AverageFieldSize>12</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item10">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item11">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item12">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item13">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item14">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item15">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item16">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item17">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item18">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item19">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item2">
<AverageFieldSize>7</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item20">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item3">
<AverageFieldSize>6</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item4">
<AverageFieldSize>8</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item5">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item6">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item7">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item8">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item9">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="ItemType">
<AverageFieldSize>4</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<SQLMap name="IDKEY">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourDateCtloc">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourDateSpot">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourUser">
<BlockCount>-4</BlockCount>
</SQLMap>
<StreamLocation>^Nur.MNISV3.SpotTourRecS</StreamLocation>
<Type>%Storage.Persistent</Type>
}

}
